#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
const int N = 1e4 + 10;
int mp[N][N];
int dis[N];
bool st[N];
int n;
int dijkstra(int x)
{
	memset(dis, 0x3f, sizeof(dis));
	dis[x] = 0;
	for (int i = 0; i < n; i++) {
		int t = -1;
		for (int j = 1; j <= n; j++) {
			if (!st[j] && (t == -1 || dis[t] > dis[j])) {
				t = j;
			}
		}
		st[t] = 1;
		for (int j = 1; j <= n; j++) {
			dis[j] = min(dis[j], dis[t] + mp[t][j]);
		}
	}
	if (dis[n] == 0x3f3f3f3f) {
		return -1;
	}
	return dis[n];
}

int spfa(int x)
{
	memset(dis, 0x3f, sizeof(dis));
	queue<int>q;
	q.push(x);
	st[x] = 1;
	while (q.size()) {
		int t = q.front();
		q.pop();
		st[t] = 0;
		for (int i = h[t]; ~i; i = ne[i]) {
			int j = e[i];
			if (dis[j] > dis[t] + w[i]) {
				dis[j] = dis[t] + w[i];
				if (!st[j]) {
					q.push(j);
					st[j] = 1;
				}
			}
		}
	}
	if (dis[n] == 0x3f3f3f3f) {
		return -1;
	}
	return dis[n];
}

int main()
{
	
	return 0;
}